/**
* 
* Sonde system specific sonde for processor 
* Copyright (c) 2009 Ecole Centrale de Nantes IRCCyN  
* 
* see <a href="{@docRoot}/Documentation/sonde.html"> for more information</a>
* 
* @author: Urunuela Richard
* @version 3.2
*/
package report;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;

import programme.GUI.JConsole;

import storm.SimulationKernel;
import storm.Processors.Processor;
import storm.Tasks.Task;

public class task extends sonde {

	private Task owner;
	private JConsole console;
	
	/**
	 * new sonde
	 * @param theOutPut
	 * @param kernel
	 */
	public task(output theOutPut, Task owner,JConsole console) {
		this.theOutPut = theOutPut;
		this.owner = owner;
		this.theOutPut.appendSection("Task " + this.owner.getName()+ " with id " + this.owner.getId());
		this.console = console;
	}
	/**
	 *  Parse specific  command from report file
	 *  internal data is specific onwn field (not calculate) 
	 */
	public void internalData(String commande) {
		//if (commande.compareToIgnoreCase("gantt")>0){
		if (commande.contains("gantt")){	
			this.console.closeall(null);
			this.console.gantt(new StringTokenizer(""+this.owner.getId()));
			String[] param = commande.split("gantt", -1);
			//this.console.afficheError(param[1]);
			this.console.setpos(new StringTokenizer("0 "+param[1]));
			
			this.console.printjpeg(new StringTokenizer("0 /tmp/tmp.jpg"));
			this.theOutPut.addImage("/tmp/tmp.jpg",75);
		}
		
		if (commande.compareToIgnoreCase("normal_exec")==0){
			this.theOutPut.addligne("Normal End : " +  this.owner.getNormalExec());
		}
		
		
		if (commande.compareToIgnoreCase("info")==0){
			
		}
		
		if (commande.compareToIgnoreCase("rtime")==0){
			Task T = this.owner;

			this.theOutPut.addligne("response time");
			this.theOutPut.addligne(T.getResponseTime());
			
			
		}
		
		if (commande.compareToIgnoreCase("stat")==0){
			
			this.theOutPut.addligne("stat");
			
		
			
			
		}
		if (commande.compareToIgnoreCase("trace")==0){
			Vector info = new Vector();
			this.theOutPut.addligne("");
			info.add("Tick");
			info.add("ET");
			info.add("RET");
			info.add("AET");
			info.add("Running");
			this.theOutPut.add(info);
			classSonde sonde = this.owner.getMySonde();
		 for (int j = 0; j < sonde.getNombreligne();j++){
				Vector vec = sonde.getligne(j);
				this.theOutPut.add(vec);
			}
			
			

		}
		
	}

}
